import { createRouter, createWebHistory } from 'vue-router'

// 基础页面布局
import BaseLayout from '../layouts/BaseLayout.vue'

// 懒加载路由
const routes = [
  {
    path: '/',
    component: BaseLayout,
    children: [
      {
        path: '',
        name: 'home',
        component: () => import('../views/Home.vue'),
        meta: { title: '功能菜单' }
      },
      // H5辅导员端
      {
        path: '/counselor/role-confirm',
        name: 'counselorRoleConfirm',
        component: () => import('../views/counselor/RoleConfirm.vue'),
        meta: { title: '辅导员角色确认' }
      },
      {
        path: '/counselor/report-records',
        name: 'counselorReportRecords',
        component: () => import('../views/counselor/ReportRecords.vue'),
        meta: { title: '上报记录' }
      },
      {
        path: '/counselor/role-switch',
        name: 'counselorRoleSwitch',
        component: () => import('../views/counselor/RoleSwitch.vue'),
        meta: { title: '角色切换' }
      },
      {
        path: '/counselor/exempt-report',
        name: 'counselorExemptReport',
        component: () => import('../views/counselor/ExemptReport.vue'),
        meta: { title: '免上报登记' }
      },
      
      // H5学院端
      {
        path: '/college/role-confirm',
        name: 'collegeRoleConfirm',
        component: () => import('../views/college/RoleConfirm.vue'),
        meta: { title: '学院角色确认' }
      },
      {
        path: '/college/counselor-reports',
        name: 'collegeCounselorReports',
        component: () => import('../views/college/CounselorReports.vue'),
        meta: { title: '辅导员上报记录' }
      },
      {
        path: '/college/confirm-records',
        name: 'collegeConfirmRecords',
        component: () => import('../views/college/ConfirmRecords.vue'),
        meta: { title: '学院确认记录' }
      },
      {
        path: '/college/role-switch',
        name: 'collegeRoleSwitch',
        component: () => import('../views/college/RoleSwitch.vue'),
        meta: { title: '角色切换' }
      },
      {
        path: '/college/exempt-report',
        name: 'collegeExemptReport',
        component: () => import('../views/college/ExemptReport.vue'),
        meta: { title: '免上报登记' }
      },
      
      // H5学校端
      {
        path: '/school/role-query',
        name: 'schoolRoleQuery',
        component: () => import('../views/school/RoleQuery.vue'),
        meta: { title: '学校角色查询' }
      },
      {
        path: '/school/college-confirm-records',
        name: 'schoolCollegeConfirmRecords',
        component: () => import('../views/school/CollegeConfirmRecords.vue'),
        meta: { title: '学院确认记录' }
      },
      {
        path: '/school/all-report-records',
        name: 'schoolAllReportRecords',
        component: () => import('../views/school/AllReportRecords.vue'),
        meta: { title: '全校上报记录' }
      },
      {
        path: '/school/role-switch',
        name: 'schoolRoleSwitch',
        component: () => import('../views/school/RoleSwitch.vue'),
        meta: { title: '角色切换' }
      },
      {
        path: '/school/exempt-report',
        name: 'schoolExemptReport',
        component: () => import('../views/school/ExemptReport.vue'),
        meta: { title: '免上报登记' }
      },
      {
        path: '/school/report-time',
        name: 'schoolReportTime',
        component: () => import('../views/school/ReportTime.vue'),
        meta: { title: '上报时间' }
      },
      
      // PC学校端
      {
        path: '/pc-school/member-management',
        name: 'pcSchoolMemberManagement',
        component: () => import('../views/pc/MemberManagement.vue'),
        meta: { title: '成员管理' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局前置守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router